import {
  navigateTo,
  getStorageSync,
  removeStorageSync
} from '@/common/js/tool'
var code = {
  ing: true
}
var request = (config, doSuccess) => {
  let token = getStorageSync('token')
  if (token) {
    config.header = config.header ? config.header : {}
    config.header.token = token
  }
  
  uni.request({
    url: config.url,
    data: config.data,
    header: config.header,
    method: config.method,
    success: (res) => {
      switch (res.data.code) {

        case 401: {
          if (code.ing) {
            // uni.showToast({
            //   mask: true,
            //   title: '请先登录',
            //   icon: 'none',
            //   duration: 2000
            // })  
            
            
            uni.showModal({
            	title: '登录提示',
            	content: '当前需要登录,点确定前往',
            	success:  (res) => {
            		if (res.confirm) {
            			  // console.log('用户点击确定');
                      uni.navigateTo({
                         url : '/pages/login/login'
                      })
            		} else if (res.cancel) {
            			  //console.log('用户点击取消');
            		}
            	}
            });
            
            // code.ing = false
            removeStorageSync('token')
            removeStorageSync('userinfo')
            removeStorageSync('location')
            removeStorageSync('history')
            removeStorageSync('address')
         
            setTimeout(() => {
              // code.ing = true
              // navigateTo({
              // 	url: '/pages/login/login'
              // })
            }, 500);
          }

        }
        break;
      default: {
        if (typeof doSuccess == 'function') {
          doSuccess(res.data)
        }
      }
      }
    }
  });
}

var url = "https://ddmy.dandanjingxi.cn/addons/kdbshop";
// var url = "http://www.ddshop.com/addons/kdbshop";

//var url = "https://baseshop.windstars.net/addons/kdbshop"
// var url = 'http://192.168.2.45:8099/addons/kdbshop';

var api = {
  main_tone: url + "/common/init", //颜色接口
  wxmobile: url + "/user/wxmobile", //微信手机修改
  profile: url + "/user/profile", //修改会员个人信息
  jscode2session: url + "/user/jscode2session", //微信无感登陆
  decrypt: url + "/user/decrypt", //微信密文解密
  listTemplate: url + "/addon_applet/listTemplate", //列出所有订阅消息
  getCommunityHeadList: url + "/community_head/getCommunityHeadList", //团长列表
  getDbtabar: url + "/dbtabar/getDbtabar", //首页导航
  getBanner: url + "/adv/getBanner", //首页轮播
  rushGoods: url + "/goods/rushGoods", //抢购列表
  get_goods_detail: url + "/goods/get_goods_detail", //商品详情页
  add: url + "/cart/add", //加入购物车
  checkoutFlushall: url + "/cart/checkoutFlushall", //勾选商品/数量加减
  checkedGoods: url + "/cart/checkedGoods", //勾选商品传参改变
  changeGoodsNum: url + "/cart/changeGoodsNum", //数量加减
  removGoods: url + "/cart/removGoods", //删除商品
  show_cart_goods: url + "/cart/show_cart_goods", //购物车
  carCount: url + "/cart/carCount", //购物车商品数
  checkout: url + "/orders/checkout", //提交订单
  orderPay: url + "/orders/orderPay", //付款
  payAgain: url + "/orders/payAgain", //订单再次付款
  receive_order: url + "/orders/receive_order", //确认收货
  goodsCategory: url + "/index/goodsCategory", //商品分类
  categoryGoods: url + "/Index/categoryGoods", //分类商品
  orderList: url + "/Orders/orderList", //订单列表
  refundList: url + "/Orders/refundList", //售后列表
  orderInfo: url + "/Orders/orderInfo", //订单详情
  batch_add: url + "/goods_comment/batch_add", //批量添加评论
  expressShow: url + "/express/show", //查看快递轨迹
  addAddress: url + "/Index/addAddress", //添加地址
  editAddress: url + "/Index/editAddress", //修改地址
  addressList: url + "/Index/addressList", //地址列表
  addressRemove: url + "/address/remove", //删除地址
  upOrderState: url + "/orders/upOrderState", //更新订单状态
  buyAgain: url + "/orders/buyAgain", //再来一单
  refundOrder: url + "/orders/refundOrder", //申请退款
  refundInfo: url + "/orders/refundInfo", //售后详情
  expressIndex: url + "/express/index", //查看快递公司列表
  upExpressNo: url + "/orders/upExpressNo", //更新退款快递
  canceRefund: url + "/orders/canceRefund", //取消退款
  userCenter: url + "/index/userCenter", //个人中心
  couponIndex: url + "/coupon/index", //可领取优惠券列表
  couponUser: url + "/coupon/user", //用户已领取优惠券
  couponReceive: url + "/coupon/receive", //领取优惠券
  distributionIndex: url + "/distribution/index", //我的团队
  distributionInvited: url + "/distribution/invited", //查看我推广的用户
  distributionMoney: url + "/distribution/money", //查看我推广的收入明细
  distributionPoster: url + "/distribution/poster", //获得推广海报
  getLogo: url + "/index/getLogo", //获得logo
  commonUpload: url + "/common/upload", //上传文件
  community_headUpdateShop: url + "/community_head/updateShop", //更新团长信息
  community_headAdd: url + "/community_head/add", //申请成为团长
  community_headShow: url + "/community_head/show", //店长信息
  community_headOrders: url + "/community_head/orders", //查看自己门店的订单列表
  user_extractCash: url + "/user_extract/cash", //提现申请
  user_extractHistory: url + "/user_extract/history", //查看我提现历史记录
  store_bargainList: url + "/store_bargain/index", //助力列表
  store_bargainMylist: url + "/store_bargain/myList", //我的助力列表
  store_bargainDetail: url + "/store_bargain/detail", //助力详情
  store_bargainHelp: url + "/store_bargain/help", //为别人助力
  store_bargainStart: url + "/store_bargain/start", //参与助力
  store_combinationIndex: url + "/store_combination/index", //拼团列表
  store_combinationDetail: url + "/store_combination/detail", //拼团产品详情
  store_combinationPink: url + "/store_combination/pink", //拼团
  store_combinationRemove: url + "/store_combination/remove", //拼团 取消拼团
  store_combinationPoster: url + "/store_combination/poster", //拼团海报
  store_seckillList: url + "/store_seckill/list", //秒杀列表
  store_seckillDetail: url + "/store_seckill/detail", //秒杀详情
  getCoupon: url + "/coupon/all", // 领券中心
  receiveCoupon: url + "/coupon/receive", //点击领券	
  goods_comment: url + "/goods_comment/index", // 商品评论
  get_adv: url + "/adv/index",
  get_region: url + "/area/index", // 获取地区
  get_vip_index: url + "/vip/index", // 会员卡列表
  buy_vip: url + "/vip/routine", // 购买会员卡
  recharge_index: url + "/recharge/index", // 获取充值列表
  vip_show: url + "/vip/show", // 会员卡优惠券
  recharge_routine: url + "/recharge/routine", // 选择套餐并充值
  recharge_money: url + "/recharge/money", // 余额充值明细
  channelf: url + "/channel/channel_list", // 文章分类
  archivesList: url + "/archives/archives_list", // 按文章分类id查询
  archivesDet: url + "/archives/archives", // 按文章分类aid查询
  forward_add: url + "/archives/forward_add", // 浏览与转发--添加 
  adv: url + "/adv/index", // 首页轮播
  forward: url + "/archives/forward", // 浏览与转发
  archives_select: url + "/archives/archives_select", // 模糊搜索
  card_detail: url + "/user/card_detail", //  查看我的名片 
  card_edit: url + "/user/update_card", //  修改名片 
  business_list: url + "/business/business_list", //  商机列表
  saveBusiness: url + "/business/saveBusiness", //  新增商机 
  FreeAdmission: url + "/user/FreeAdmission", //  试用
  newPoster: url + "/distribution/poster_distribute", //获得推广海报
  PhoneWeChat: url + "/user/PhoneWeChat", //首页电话微信
  getIndivi: url + "/archives/forward_to", //具体人的信息

  userDetail: url + "/user/user_detail", // 查看我的客户信息
  getSpecial: url + "/special/special_list", // 专题页接口
  tagAdd: url + "/user/tag_add", // 客户添加标签
  article: url + "/special/special_article", // 专题文章列表

  // 拱配
  cooperativeInstitutions: url + "/Adv/index", // 专题文章列表
  aboutus: url + "/article/show", //  关于我们
  getIndexBanner: url + '/adv/getIndexBanner', //所有图

  //丹樱
  supply: url + '/community_head/supply', //对扫码后的结果发起请求
  supplycheck: url + '/order_code/check', //订单商品单个核销
  supplyhistory: url + '/order_code/history', //核销历史订单
  codeshow: url + '/order_code/show', //订单商品的核销码列表

  setAppointmentTime: url + '/cart/setAppointmentTime', //设置预约信息
  appointment: url + '/cart/appointment', //查看指定日期指定时间的预约信息 

  //绣造
  getroutine: url + '/special_order/routine', //小程序购买课程
  getSpecialuser: url + '/special/special_user', //已付款课程
  showcard: url + '/vip/show_card', // 查看已购买会员卡与教育班
  showcode: url + '/vip/show_code', //查看会员卡二维码
  actingclass: url + '/vip/acting_class', //升级代理班--列表
  recordclass: url + '/vip/record_class', //升级代理班--记录
  usermoney: url + '/user/user_money', //我的余额
  viprecommend: url + '/vip/recommend', //推荐V1
  getaxtract_moeny: url + '/user_extract/money', //查看我佣金明细
  getagent_money: url + '/user_extract/agent_money', //查看我代理明细
  vipwrite: url + '/vip/write_off', //使用明细
  vipnew_card: url + '/vip/new_card', //赠送券
  broadcast: url + '/broadcast/broadcast_list', //直播
  broadcastids: url + '/broadcast/broadcast_ids', //直播

  // 旗
  getuser_orders: url + "/orders/user_orders", //查看会员订单
  give_receive: url + '/vip/give_receive', //转赠
  give_is_about: url + '/vip/give_is_about', //转赠
  index_data: url + '/index/index_data', //首页数据\
  recharge_show: url + '/recharge/show', //会员卡
  user_card: url + '/orders/user_card', //可用的会员卡
  index_user: url + '/recharge/index_user', //充值-已购买会员
  reuser_money: url + '/recharge/user_money', //会员卡消费记录
  recharge_code: url + '/recharge/recharge_code', //查看二维码
  show_card_detail: url + "/vip/show_card_detail", //查看已购买会员卡与教育班
  routine_pay: url + '/vip/routine_pay', //套餐
  routine_count: url + '/vip/routine_count', //
  overstep: url + '/appointment/overstep', //是否约满

  // 海钓船

  gift_card_index: url + '/gift_card/index', //礼品卡
  gift_card_my: url + '/gift_card/my', //我的礼品卡
  gift_card_exchange: url + '/gift_card/exchange', //礼品卡兑换余额
  gift_card_show: url + '/gift_card/show', //查看礼品卡详情
  gift_card_routine: url + '/gift_card/routine', //购买礼品卡

  integral_category: url + '/goods/integral_category', //GET 查找所有积分分类 
  integralPay: url + '/orders_integral/integralPay', // 支付积分
  integral_list: url + '/orders_integral/integral_list', // 积分兑换记录

}

export default {
  url,
  request,
  api
}
